<template>
    <div>

      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            fixed
            prop="id"
            label="id"
            width="100">
        </el-table-column>
        <el-table-column
            prop="ingredientsName"
            label="原料厂商负责人"
            width="100">
        </el-table-column>
        <el-table-column
            prop="processingStatus"
            label="加工状态"
            width="150">
        </el-table-column>
        <el-table-column
            prop="stashStatus"
            label="库状态"
            width="150">
        </el-table-column>
        <el-table-column
            prop="cropId"
            label="作物编号"
            width="150">
        </el-table-column>
        <el-table-column
            prop="cropName"
            label="作物名称"
            width="150">
        </el-table-column>
        <el-table-column
            prop="cropRule"
            label="吨数"
            width="150">
        </el-table-column>
        <el-table-column
            prop="num"
            label="数量"
            width="150">
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <span v-if="scope.row.processingStatus=='未加工'">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="gojia(scope.row)"
                  v-hasPermi="['system:dict:edit']"
              >去加工</el-button>
            </span>

            <span v-if="scope.row.stashStatus=='待处理'">
            <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="gostorage(scope.row)"
                v-hasPermi="['system:dict:remove']"
            >去入库</el-button></span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @current-change="gopage"
          :page-size="size"
          layout="total, prev, pager, next"
          :total="total">
      </el-pagination>


      <el-dialog center title="加工" :visible.sync="jiaopen" width="700px" append-to-body>
        <el-form ref="form" label-width="80px" :model="jiaForm">
          <el-row>
            <el-col :span="15">
              <el-form-item label="输入加工规则" prop="nickName">
                <el-input v-model="jiaForm.size" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="输入加工质量" prop="nickName">
                <el-input v-model="jiaForm.standard" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="输入加工数量" prop="nickName">
                <el-input v-model="jiaForm.num" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" type="primary" @click="goprocess">确 定</el-button>
          <el-button size="mini" @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog center title="入库" :visible.sync="open" width="700px" append-to-body>
        <el-form ref="form" label-width="80px" :model="cropperForm">
          <el-row>
            <el-col :span="15">
              <el-form-item label="请选择仓库" prop="nickName">
                <el-select v-model="cropperForm.stashfId" placeholder="请选择" @change="changestashId">
                  <el-option v-for="s in fstashList" :key="s.id"   :label="s.name" :value="s.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="15">
              <el-form-item label="请选择库区" prop="nickName">
                <el-select v-model="cropperForm.stashId" placeholder="请选择">
                  <el-option v-for="s in stashList" :key="s.id"   :label="`${s.id}，${s.name} (${s.status},${s.standard}吨,尺寸:${s.size}*${s.size})`" :value="s.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" type="primary" @click="recordCropsGrow">确 定</el-button>
          <el-button size="mini" @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

    </div>
</template>

<script>
export default {
  name: "ProdprocessingView",
  data(){
    return{
      tableData:[],
      cropperForm:{},
      stashList:[],
      open:false,
      jiaopen:false,
      size:3,
      total:0,
      current:1,
      sizeList:[],
      jiaForm:{},
      fstashList:[],
    }
  },methods:{
    gopage(current){
      this.current=current;
      this.list();
    },
    getfstashList(){
      this.axios.post("/cropservice/crop/getfstashList").then(res=>{
        if(res.data.code==200){
          this.fstashList=res.data.data;
        }
      })
    },
    gojia(row){
      this.jiaForm=row;
      this.jiaopen=true;
    },
    changestashId(id){
      this.axios.post("/cropservice/crop/getstash?stashfId="+id,this.cropperForm).then(res=>{
        if(res.data.code==200){
          // this.cropperForm.stashId=null;
          this.stashList=res.data.data;
        }
      })
    },

    goprocess(){
      this.axios.post("/cropservice/crop/gopress",this.jiaForm).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          this.jiaopen=false;
          this.list();
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    recordCropsGrow(){
      this.axios.post("/cropservice/crop/gostorage?stashId="+this.cropperForm.stashId+"&fstashId="+this.cropperForm.stashfId,this.cropperForm).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          this.open=false;
          this.list();
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    gostorage(row){
      // this.cropperForm={stashId:null}
      this.cropperForm=row;
      this.open=true;
      this.getfstashList();
    },
    list(){
      this.axios.post("/cropservice/crop/produpresslist?current="+this.current+"&size="+this.size).then(res=>{
        if(res.data.code==200){
          this.tableData=res.data.data.list;
          this.total=res.data.data.total;
        }
      })
    }
  },created() {
      this.list();
  },

}
</script>

<style scoped>

</style>